package com.qzsoft.zhjd.asphalt.modules.asphalthomepage.controller;

import cn.hutool.json.JSONObject;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.system.modules.sysstation.entity.SysStationEntity;
import com.qzsoft.zhjd.asphalt.modules.asphalthomepage.service.HomePageService;
import com.qzsoft.zhjd.asphalt.modules.asphalthomepage.dto.ProductionDataBaseDTO;
import com.qzsoft.zhjd.asphalt.modules.asphalthomepage.dto.AsphaltDataWeightDTO;
import com.qzsoft.zhjd.asphalt.modules.asphalthomepage.dto.AsphaltMonthAndYearCountDto;
import com.qzsoft.zhjd.asphalt.modules.asphalthomepage.dto.AsphaltMonthCountDto;
import com.qzsoft.zhjd.asphalt.modules.asphalthomepage.dto.GetCostAdjustmentDTO;
import com.qzsoft.zhjd.asphalt.modules.asphalthomepage.dto.OmitDepthOutputAtEachBaseDTO;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 沥青拌和站首页接口
 */
@RestController
@RequestMapping("/api/asphaltHomePage")
public class HomePageController {
    @Autowired
    private HomePageService homePageService;

    /**
     * @Title countByYear
     * @Description 养护基地指定年份产量统计
     * @param baseCode 养护基地编码
     * @param year     统计年份
     * @return 产量统计
     */
    @GetMapping("countByYear")
    public Result<BigDecimal> countByYear(@RequestParam(required = true) String baseCode,
            @RequestParam(required = true) String year) {
        BigDecimal data = homePageService.countByYear(baseCode, year);
        return ResultUtils.ok(data);
    }

    /**
     * @Title countForMonth
     * @Description 养护基地指定年份月产量统计
     * @param baseCode 养护基地编码
     * @param year     统计年份
     * @return 月产量统计
     */
    @GetMapping("countForMonth")
    public Result<List<AsphaltMonthCountDto>> countForMonth(@RequestParam(required = true) String baseCode,
                                                            @RequestParam(required = true) String year) {
        List<AsphaltMonthCountDto> data = homePageService.countForMonth(baseCode, year);
        return ResultUtils.ok(data);
    }

    /**
     * 产量统计
     *
     * @param params
     * @return
     */
    @GetMapping("/omitDepthOutputAtEachBase")
    public Result<OmitDepthOutputAtEachBaseDTO> omitDepthOutputAtEachBase(@RequestParam Map<String, Object> params) {
        OmitDepthOutputAtEachBaseDTO data = homePageService.omitDepthOutputAtEachBase(params);
        return ResultUtils.ok(data);
    }

    /**
     * 材料成本核算
     *
     * @param params
     * @return
     */
    @GetMapping("/getCostAdjustment")
    public Result<List<GetCostAdjustmentDTO>> getCostAdjustment(@RequestParam Map<String, Object> params) {
        List<GetCostAdjustmentDTO> data = homePageService.getCostAdjustment(params);
        return ResultUtils.ok(data);
    }

    /**
     * 产量情况
     *
     * @param params
     * @return
     */
    @GetMapping("/plantProduction")
    public Result<List<JSONObject>> plantProduction(@RequestParam Map<String, Object> params) {
        List<JSONObject> data = homePageService.plantProduction(params);
        return ResultUtils.ok(data);
    }

    /**
     * 项目供应情况
     *
     * @param params
     * @return
     */
    @GetMapping("/estimatedTimeOfDelivery")
    public Result<List<JSONObject>> estimatedTimeOfDelivery(@RequestParam Map<String, Object> params) {
        List<JSONObject> data = homePageService.estimatedTimeOfDelivery(params);
        return ResultUtils.ok(data);
    }

    /**
     * 实时生产情况
     *
     * @param params
     * @return
     */
    @GetMapping("/realTimeProduction")
    public Result<List<AsphaltDataWeightDTO>> realTimeProduction(@RequestParam Map<String, Object> params) {
        List<AsphaltDataWeightDTO> data = homePageService.realTimeProduction(params);
        return ResultUtils.ok(data);
    }

    /**
     * @Title details
     * @Description 查看
     * @param id 数据主键
     * @return 数据详情
     */
    @GetMapping("/details/{id}")
    public Result<ProductionDataBaseDTO> details(@PathVariable("id") String id) {
        ProductionDataBaseDTO data = homePageService.details(id);
        return ResultUtils.ok(data);
    }

    /**
     * @Title getStations
     * @Description 获取拌合楼列表
     * @param params 查询条件
     * @return 拌合楼列表
     */
    @GetMapping("/getStations")
    public Result<List<SysStationEntity>> getStations(@RequestParam Map<String, Object> params) {
        List<SysStationEntity> data = homePageService.getTokenStart(params);
        return ResultUtils.ok(data);
    }

    /**
     * @Title getCountByMonthAndYear
     * @Description 获取指定月份、年度产量
     * @param baseCode 基地编号
     * @param month 月份
     * @param year  年份
     * @return 指定月份、年度产量
     */
    @GetMapping("/getCountByMonthAndYear")
    public Result<AsphaltMonthAndYearCountDto> getCountByMonthAndYear(@RequestParam(required = true) String baseCode,
            @RequestParam(required = false) String month, @RequestParam(required = false) String year) {
        AsphaltMonthAndYearCountDto data = homePageService.getCountByMonthAndYear(baseCode, month, year);
        return ResultUtils.ok(data);
    }
}
